import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import account from './account'

// import example from './module-example'

Vue.use(Vuex)

/*
 * If not building with SSR mode, you can
 * directly export the Store instantiation;
 *
 * The function below can be async too; either use
 * async/await or return a Promise which resolves
 * with the Store instance.
 */

export default function (/* { ssrContext } */) {
  const Store = new Vuex.Store({
    modules: {
      account
    },
    state,
    mutations: {
      changeLogin (state, user) {
        state.Authorization = user.Authorization
        state.Author = user.Author
        state.Roles = user.Roles
        state.Theme = user.Theme
        localStorage.setItem('Authorization', user.Authorization)
        localStorage.setItem('Author', user.Author)
        localStorage.setItem('Roles', user.Roles)
        localStorage.setItem('Theme', user.Theme)
      },
      changeTheme (state, user) {
        state.Theme = user.Theme
        localStorage.setItem('Theme', user.Theme)
      },
      clearLogin () {
        localStorage.removeItem('Authorization')
        localStorage.removeItem('Author')
        localStorage.removeItem('Roles')
      },

    },

    // enable strict mode (adds overhead!)
    // for dev mode only
    strict: process.env.DEBUGGING
  })

  return Store
}
